package net.homeip.jcperera.webinfo;

import java.io.Serializable;
import java.util.Calendar;
import java.util.HashSet;
import java.util.Set;

import javax.inject.Named;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Inheritance;
import javax.persistence.InheritanceType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import net.homeip.jcperera.nu.core.utils.DateUtil;
import net.homeip.jcperera.nu.model.entity.PersistentEntity;

@Entity
@Table(name = ScanProfile.tableName)
@Named(ScanProfile.componentName)
@Inheritance(strategy = InheritanceType.JOINED)
public class ScanProfile extends PersistentEntity implements Serializable
{
    private static final long         serialVersionUID      = 2844054808917877040L;

    // CoreBase properties, for easy use from other components, as well as logging
    public static final int           runtimeLevel          = 5;
    public static final String        moduleName            = "webinfo";
    public static final String        componentName         = "webinfo_scanprofile";

    // All persistent entities should specify a table name
    public static final String        tableName             = "SCAN_PROFILE";

    @Basic
    @Column(name = "NAME")
    private String                    name                  = "";

    @Basic
    @Column(name = "PERIODICITY")
    private Integer                   periodicity           = 1;

    @Basic
    @Column(name = "PERIODICITYUNIT")
    private DateUtil.Periodicity      periodicityUnit       = DateUtil.Periodicity.DAY;

    @Basic
    @Column(name = "ISRUNNING")
    private Boolean                   isRunning             = false;

    @Basic
    @Column(name = "FETCHNEXTDELAY")
    private Integer                   fetchNextDelay        = 1;

    @Enumerated(EnumType.STRING)
    @Column(name = "FETCHNEXTDELAYUNIT")
    private DateUtil.Periodicity      fetchNextDelayUnit    = DateUtil.Periodicity.SECOND;

    @Basic
    @Column(name = "TOLERANCE")
    private Integer                   tolerance             = 1;

    @Enumerated(EnumType.STRING)
    @Column(name = "TOLERANCEUNIT")
    private DateUtil.Periodicity      toleranceUnit         = DateUtil.Periodicity.SECOND;

    @Basic
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "LASTRUNSTARTED")
    private Calendar                  lastRunStarted        = null;

    @Basic
    @Temporal(TemporalType.TIMESTAMP)
    @Column(name = "LASTRUNSTOPPED")
    private Calendar                  lastRunStopped        = null;

    @Basic
    @Column(name = "HOWMANYUP")
    private Integer                   howManyUp             = 0;

    @Basic
    @Column(name = "HOWMANYDOWN")
    private Integer                   howManyDown           = 0;

    @ManyToOne
    @JoinColumn(name = "SITE", nullable = false)
    private WebInfoSite               site;

    @OneToMany(cascade = CascadeType.ALL, mappedBy = "scanProfile")
    private Set<ScanProfileParameter> scanProfileParameters = new HashSet<ScanProfileParameter>();

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Integer getPeriodicity()
    {
        return periodicity;
    }

    public void setPeriodicity(Integer periodicity)
    {
        this.periodicity = periodicity;
    }

    public DateUtil.Periodicity getPeriodicityUnit()
    {
        return periodicityUnit;
    }

    public void setPeriodicityUnit(DateUtil.Periodicity periodicityUnit)
    {
        this.periodicityUnit = periodicityUnit;
    }

    public Boolean getIsRunning()
    {
        return isRunning;
    }

    public void setIsRunning(Boolean isRunning)
    {
        this.isRunning = isRunning;
    }

    public Integer getFetchNextDelay()
    {
        return fetchNextDelay;
    }

    public void setFetchNextDelay(Integer fetchNextDelay)
    {
        this.fetchNextDelay = fetchNextDelay;
    }

    public DateUtil.Periodicity getFetchNextDelayUnit()
    {
        return fetchNextDelayUnit;
    }

    public void setFetchNextDelayUnit(DateUtil.Periodicity fetchNextDelayUnit)
    {
        this.fetchNextDelayUnit = fetchNextDelayUnit;
    }

    public Integer getTolerance()
    {
        return tolerance;
    }

    public void setTolerance(Integer tolerance)
    {
        this.tolerance = tolerance;
    }

    public DateUtil.Periodicity getToleranceUnit()
    {
        return toleranceUnit;
    }

    public void setToleranceUnit(DateUtil.Periodicity toleranceUnit)
    {
        this.toleranceUnit = toleranceUnit;
    }

    public Calendar getLastRunStarted()
    {
        return lastRunStarted;
    }

    public void setLastRunStarted(Calendar lastRunStarted)
    {
        this.lastRunStarted = lastRunStarted;
    }

    public Calendar getLastRunStopped()
    {
        return lastRunStopped;
    }

    public void setLastRunStopped(Calendar lastRunStopped)
    {
        this.lastRunStopped = lastRunStopped;
    }

    public Integer getHowManyUp()
    {
        return howManyUp;
    }

    public void setHowManyUp(Integer howManyUp)
    {
        this.howManyUp = howManyUp;
    }

    public Integer getHowManyDown()
    {
        return howManyDown;
    }

    public void setHowManyDown(Integer howManyDown)
    {
        this.howManyDown = howManyDown;
    }

    public WebInfoSite getSite()
    {
        return site;
    }

    public void setSite(WebInfoSite site)
    {
        this.site = site;
    }

    public Set<ScanProfileParameter> getScanProfileParameters()
    {
        return scanProfileParameters;
    }

    public void setScanProfileParameters(Set<ScanProfileParameter> scanProfileParameters)
    {
        this.scanProfileParameters = scanProfileParameters;
    }
}
